/****************************************************************************
**
****************************************************************************/

#include <sys/time.h>

#include "recordMain.h"
#include "oiovCallback.h"
#include "controllerMain.h"
#include "oiovMain.h"
#include "iotUpgradeMain.h"

#include "../../iov/feestrategy-lib/inc/app_fee_strategy.h"
#include "../../iov/operation/operation_interface.h"
#include "../../controller/controller_can.h"

#include <iostream>
#include <string>
#include <cstring>
#include <sstream>

#include <QDebug>
#define OPERATION_DEBUG

/*-----------------------------------------------------------------------------------------*/

/* 充电桩登陆签到（接入认证）请求报文 */
ops_event_sign_in_t OiovCallback::ops_event_sign_in[OPS_MAX_PORT_NUM] = {};

/* 充电桩心跳请求报文 */
ops_event_heartbeat_t OiovCallback::ops_event_heartbeat[OPS_MAX_PORT_NUM] = {};

/* 充电桩计费策略请求报文 */
ops_event_fee_strategy_t OiovCallback::ops_event_fee_strategy;

/* 充电桩账单请求报文 */
ops_event_bill_t OiovCallback::ops_event_bill[OPS_MAX_PORT_NUM] = {};
ops_event_bill_t OiovCallback::ops_event_rebill;

/* 充电桩主动申请充电报文*/
ops_event_card_authorize_t OiovCallback::ops_event_card_authorize[OPS_MAX_PORT_NUM] = {};

/* BMS各阶段上报*/
ops_event_charge_handshake_t       OiovCallback::ops_event_charge_handshake[OPS_MAX_PORT_NUM];
ops_event_set_value_t              OiovCallback::ops_event_set_value[OPS_MAX_PORT_NUM];
ops_event_charge_complete_t        OiovCallback::ops_event_charge_complete[OPS_MAX_PORT_NUM];
ops_event_error_t                  OiovCallback::ops_event_error[OPS_MAX_PORT_NUM];
ops_event_charge_abort_t           OiovCallback::ops_event_charge_abort[OPS_MAX_PORT_NUM];
ops_event_charge_stop_t            OiovCallback::ops_event_charge_stop[OPS_MAX_PORT_NUM];
ops_event_charge_output_t          OiovCallback::ops_event_charge_output[OPS_MAX_PORT_NUM];
ops_event_charge_process_status_t  OiovCallback::ops_event_charge_process_status[OPS_MAX_PORT_NUM];


/* 充电桩实时数据请求报文 */
ops_property_charge_data_t OiovCallback::ops_property_charge_data[OPS_MAX_PORT_NUM] = {};

/* 云服务器时间请求报文 */
ops_active_service_time_syn_t OiovCallback::ops_active_service_time_syn;

/* 云服务器重启充电桩请求报文 */
ops_active_service_reboot_t OiovCallback::ops_active_service_reboot;

/* 云服务器启动升级请求报文 */
ops_active_service_start_update_t OiovCallback::ops_active_service_start_update[OPS_MAX_PORT_NUM] = {};

/* APP启动充电请求报文 */
ops_active_service_start_charging_app_t OiovCallback::ops_active_service_start_charging_app[OPS_MAX_PORT_NUM] = {};

/* APP停止充电请求报文 */
ops_active_service_stop_charging_app_t OiovCallback::ops_active_service_stop_charging_app[OPS_MAX_PORT_NUM] = {};

/*-----------------------------------------------------------------------------------------*/

/* 云服务器登陆签到（接入认证）应答报文 */
ops_passive_service_sign_in_t OiovCallback::ops_passive_service_sign_in[OPS_MAX_PORT_NUM] = {};

/* 云服务器心跳应答报文 */
ops_passive_service_heartbeat_t OiovCallback::ops_passive_service_heartbeat[OPS_MAX_PORT_NUM] = {};

ops_event_fee_mode_check_t     OiovCallback::ops_event_check_fee;
ops_passive_service_fee_mode_check_t     OiovCallback::ops_passive_check_fee;

/* 云服务计费策略应答报文 */
ops_passive_service_fee_strategy_t OiovCallback::ops_passive_service_fee_strategy;

/* 云服务器账单应答报文 */
ops_passive_service_bill_t OiovCallback::ops_passive_service_bill[OPS_MAX_PORT_NUM] = {};

/* 充电桩时间同步应答报文 */
ops_active_service_feedback_time_syn_t OiovCallback::ops_active_service_feedback_time_syn;

/* 充电桩重启应答报文 */
ops_active_service_feedback_reboot_t OiovCallback::ops_active_service_feedback_reboot;

/* 充电桩启动升级应答报文 */
ops_active_service_feedback_start_update_t OiovCallback::ops_active_service_feedback_start_update[OPS_MAX_PORT_NUM] = {};

/* APP启动充电应答报文 */
ops_active_service_feedback_start_charging_app_t OiovCallback::ops_active_service_feedback_start_charging_app[OPS_MAX_PORT_NUM] = {};

/* APP停止充电应答报文 */
ops_active_service_feedback_stop_charging_app_t OiovCallback::ops_active_service_feedback_stop_charging_app[OPS_MAX_PORT_NUM] = {};

/* 充电桩主动申请充电应答报文 */
ops_passive_service_card_authorize_t OiovCallback::ops_passive_service_card_authorize[OPS_MAX_PORT_NUM] = {};

/*-----------------------------------------------------------------------------------------*/

OiovCallback::OiovCallback(QObject *parent) : QObject(parent)
{
    RegisterCallback();
}

OiovCallback::~OiovCallback()
{

}

int32_t OiovCallback::callback_active_service_start_charging_app(
    ops_active_service_start_charging_app_t *request, ops_active_service_feedback_start_charging_app_t *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_active_service_start_charging_app (no:" << request->gun_number << ")";
#endif

    if ((OPSGUNNOA != request->gun_number) && (OPSGUNNOB != request->gun_number)) {
        return -1;
    }

    /* 入参 */
    memset(&ops_active_service_start_charging_app[request->gun_number - OPSGUNNOA], 0x00, sizeof(ops_active_service_start_charging_app_t));
    memcpy(&ops_active_service_start_charging_app[request->gun_number - OPSGUNNOA], request, sizeof(ops_active_service_start_charging_app_t));

    /* 出参 */
    OiovReqMain::Updata_serial_number(request->gun_number - OPSGUNNOA);
    memcpy(feedback->serial_number, ops_active_service_start_charging_app[request->gun_number - OPSGUNNOA].serial_number,
           sizeof(ops_active_service_start_charging_app[request->gun_number - OPSGUNNOA].serial_number));
    memcpy(feedback->pill_number, ops_active_service_start_charging_app[request->gun_number - OPSGUNNOA].pill_number,
           sizeof(ops_active_service_start_charging_app[request->gun_number - OPSGUNNOA].pill_number));


    feedback->gun_number = ops_active_service_start_charging_app[request->gun_number - OPSGUNNOA].gun_number;
    feedback->handle_result = OPS_LOCAL_HANDLE_RESULT_SUCCESS;
    feedback->failed_reason = 0x00;

    /* 处理 */
    if (OPS_LOCAL_HANDLE_RESULT_SUCCESS == feedback->handle_result) {
        OiovReqMain::SetAppStartChargeService(request->gun_number - OPSGUNNOA);
    }

    return 0;
}

int32_t OiovCallback::callback_active_service_stop_charging_app(
    ops_active_service_stop_charging_app_t *request, ops_active_service_feedback_stop_charging_app_t *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_active_service_stop_charging_app (no:" << request->gun_number << ")";
#endif

    if ((OPSGUNNOA != request->gun_number) && (OPSGUNNOB != request->gun_number)) {
        return -1;
    }

    /* 入参 */
    memset(&ops_active_service_stop_charging_app[request->gun_number - OPSGUNNOA], 0x00, sizeof(ops_active_service_stop_charging_app_t));
    memcpy(&ops_active_service_stop_charging_app[request->gun_number - OPSGUNNOA], request, sizeof(ops_active_service_stop_charging_app_t));

    /* 出参 */
    memcpy(feedback->pill_number, ops_active_service_stop_charging_app[request->gun_number - OPSGUNNOA].pill_number,
           sizeof(ops_active_service_stop_charging_app[0].pill_number));
    feedback->gun_number = ops_active_service_stop_charging_app[request->gun_number - OPSGUNNOA].gun_number;
    feedback->handle_result = OPS_LOCAL_HANDLE_RESULT_SUCCESS;
    feedback->failed_reason = 0x00;

    /* 处理 */
    if (OPS_LOCAL_HANDLE_RESULT_SUCCESS == feedback->handle_result) {
        OiovReqMain::SetAppStopChargeService(request->gun_number - OPSGUNNOA);
    }

    return 0;
}

int32_t OiovCallback::callback_passive_service_fee_check(ops_passive_service_fee_mode_check_t *request, void *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_passive_service_fee_check";
#endif
    /* 入参 */
    (void)request;
    memset(&ops_passive_check_fee, 0x00, sizeof(ops_passive_service_fee_mode_check_t));
    memcpy(&ops_passive_check_fee, request, sizeof(ops_passive_service_fee_mode_check_t));

    /* 出参 */
    (void)feedback;


    /* 处理 */
    if (ops_passive_check_fee.result == 0x01) {
        OiovReqMain::SetReq_Fee();
    } else {
        //
    }


    return 0;
}

int32_t OiovCallback::callback_active_service_fee_strategy(
    ops_passive_service_fee_strategy_t *request, ops_active_service_feedback_fee_strategy_t *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_active_service_fee_strategy";
#endif

    /* 入参 */
    memset(&ops_passive_service_fee_strategy, 0x00, sizeof(ops_passive_service_fee_strategy_t));
    memcpy(&ops_passive_service_fee_strategy, request, sizeof(ops_passive_service_fee_strategy_t));

    /* 出参 */
    memcpy(feedback->pill_number, ops_passive_service_fee_strategy.pill_number, sizeof(ops_passive_service_fee_strategy.pill_number));
    feedback->result = 0x01; /* 成功 */

    /* 处理 */
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_elec_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_service_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_service_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_service_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_service_fee / 10);
    for (uint8_t i = 0; i < FEE_STRATEGY_PERIOD_TPYE_MAX; i++) {
        set_fi_period_elec_type(FEE_NUMBERA, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
        set_fi_period_service_type(FEE_NUMBERA, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
    }
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_elec_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_service_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_service_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_service_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_service_fee / 10);
    for (uint8_t i = 0; i < FEE_STRATEGY_PERIOD_TPYE_MAX; i++) {
        set_fi_period_elec_type(FEE_NUMBERB, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
        set_fi_period_service_type(FEE_NUMBERB, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
    }

    return 0;
}

int32_t OiovCallback::callback_active_service_time_syn(ops_active_service_time_syn_t *request, ops_active_service_feedback_time_syn_t *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_active_service_time_syn" << request->pill_number;
#endif

    /* 入参 */
    memcpy(&ops_active_service_time_syn, request, sizeof(ops_active_service_time_syn_t));

    /* 出参 */
    memcpy(feedback->pill_number, ops_active_service_time_syn.pill_number, sizeof(ops_active_service_time_syn.pill_number));
    memcpy(feedback->time.tm, ops_active_service_time_syn.time.tm, sizeof(ops_active_service_time_syn.time.tm));

    /* 处理 */
    struct tm time_tm;
    struct timeval time;
    time_tm.tm_year = ops_active_service_time_syn.time.cp56time2a_tm.year + 2000 - 1900;
    time_tm.tm_mon = ops_active_service_time_syn.time.cp56time2a_tm.month - 1;
    time_tm.tm_mday = ops_active_service_time_syn.time.cp56time2a_tm.mday;
    time_tm.tm_hour = ops_active_service_time_syn.time.cp56time2a_tm.hour;
    time_tm.tm_min = ops_active_service_time_syn.time.cp56time2a_tm.min;
    time_tm.tm_sec = ops_active_service_time_syn.time.cp56time2a_tm.msec / 1000;
    time.tv_sec = mktime(&time_tm);
    time.tv_usec = 0;

    settimeofday(&time, NULL);
    gettimeofday(&time, NULL); //set system time

    return 0;
}

int32_t OiovCallback::callback_active_service_reboot(
    ops_active_service_reboot_t *request, ops_active_service_feedback_reboot_t *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_active_service_reboot";
#endif

    /* 入参 */
    memset(&ops_active_service_reboot, 0x00, sizeof(ops_active_service_reboot_t));
    memcpy(&ops_active_service_reboot, request, sizeof(ops_active_service_reboot_t));

    /* 出参 */
    memcpy(feedback->pill_number, ops_active_service_reboot.pill_number, sizeof(ops_active_service_reboot.pill_number));
    feedback->handle_result = 0x00;

    /* 处理 */
    //...

    return 0;
}

int32_t OiovCallback::callback_active_service_start_update(
    ops_active_service_start_update_t *request, ops_active_service_feedback_start_update_t *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_active_service_start_update";
#endif

    /* 入参 */
    memset(&ops_active_service_start_update[0], 0x00, sizeof(ops_active_service_start_update_t));
    memcpy(&ops_active_service_start_update[0], request, sizeof(ops_active_service_start_update_t));

    /* 出参 */
    (void)feedback;


    // 解析端口
    uint16_t port = request->update_port;

    // 解析其他字段
    char update_addr[17] = {0}; // +1 for null terminator
    char user[17] = {0};
    char password[17] = {0};
    char path[33] = {0};

    std::strncpy(update_addr, reinterpret_cast<char *>(request->update_addr), 16);
    std::strncpy(user, reinterpret_cast<char *>(request->user), 16);
    std::strncpy(password, reinterpret_cast<char *>(request->password), 16);
    std::strncpy(path, reinterpret_cast<char *>(request->path), 32);

    // 组合地址和端口
    char server[40] = {0}; // 足够大以容纳完整的地址和端口
    std::snprintf(server, sizeof(server), "%s:%d", update_addr, port);

    IotUpgrade::downloadFileFromFTP(server, user, password, path);

    /* 处理 */
    //...

    return 0;
}

int32_t OiovCallback::callback_passive_service_sign_in(ops_passive_service_sign_in_t *request, void *feedback)
{
    /* 入参 */
    (void)request;

    /* 出参 */
    (void)feedback;

    return 0;
}

int32_t OiovCallback::callback_passive_service_heartbeat(ops_passive_service_heartbeat_t *request, void *feedback)
{
    /* 入参 */
    (void)request;

    /* 出参 */
    (void)feedback;

    /* 处理 */
    //...

    return 0;
}

int32_t OiovCallback::callbakc_passive_service_fee_strategy(ops_passive_service_fee_strategy_t *request, void *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callbakc_passive_service_fee_strategy";
#endif

    /* 入参 */
    memset(&ops_passive_service_fee_strategy, 0x00, sizeof(ops_passive_service_fee_strategy_t));
    memcpy(&ops_passive_service_fee_strategy, request, sizeof(ops_passive_service_fee_strategy_t));

    /* 出参 */
    (void)feedback;

    OiovCallback::ops_event_check_fee.fee_mode_no =  ops_passive_service_fee_strategy.fee_model_number;

    /* 处理 */
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_elec_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_service_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_service_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_service_fee / 10);
    set_fi_price_service(FEE_NUMBERA, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_service_fee / 10);
    for (uint8_t i = 0; i < FEE_STRATEGY_PERIOD_TPYE_MAX; i++) {
        set_fi_period_elec_type(FEE_NUMBERA, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
        set_fi_period_service_type(FEE_NUMBERA, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
    }
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_elec_fee / 10);
    set_fi_price_elec(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_elec_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_SHARP, ops_passive_service_fee_strategy.sharp_service_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_PEAK, ops_passive_service_fee_strategy.peak_service_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_FLAT, ops_passive_service_fee_strategy.flat_service_fee / 10);
    set_fi_price_service(FEE_NUMBERB, FEE_STRATEGY_PRICE_TPYE_VALLEY, ops_passive_service_fee_strategy.valley_service_fee / 10);
    for (uint8_t i = 0; i < FEE_STRATEGY_PERIOD_TPYE_MAX; i++) {
        set_fi_period_elec_type(FEE_NUMBERB, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
        set_fi_period_service_type(FEE_NUMBERB, i, (enum fee_strategy_price_type)(ops_passive_service_fee_strategy.period[i]));
    }

    return 0;
}

int32_t OiovCallback::callback_passive_service_bill(ops_passive_service_bill_t *request, void *feedback)
{
    QString str;
    str.clear();
    for (size_t i = 0; i < sizeof(request->serial_number); ++i) {
        str += QString("%1").arg(request->serial_number[i], 2, 16, QLatin1Char('0')).toUpper();
    }

#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_passive_service_bill (result:" << request->handle_result << "trade_no:" << str << ")";
#endif

    /* 入参 */
    memset(&ops_passive_service_bill[0], 0x00, sizeof(ops_passive_service_bill_t));
    memcpy(&ops_passive_service_bill[0], request, sizeof(ops_passive_service_bill_t));

    /* 出参 */
    (void)feedback;

    /* 处理 */
    if (0x00 == ops_passive_service_bill[0].handle_result) {
        RecordMain::m_baseRecord.UpdateRecord("trade_no", str, "order_state", RecordMain::KOrderComplete);
    } else {
        RecordMain::m_baseRecord.UpdateRecord("trade_no", str, "order_state", RecordMain::KOrderVoided);
    }

    return 0;
}

int32_t OiovCallback::callback_passive_card_auth(ops_passive_service_card_authorize_t *request, void *feedback)
{
#ifdef OPERATION_DEBUG
    qDebug() << "[OPERATION]-> callback_passive_card_auth (no:" << request->gun_number
             << "| account:" << request->account_balance
             << "| flag:" << request->authentication_flag
             << "| reason:" << request->failed_reason << ")";
#endif

    if ((OPSGUNNOA != request->gun_number) && (OPSGUNNOB != request->gun_number)) {
        return -1;
    }

    /* 入参 */
    memset(&ops_passive_service_card_authorize[request->gun_number - OPSGUNNOA], 0x00, sizeof(ops_passive_service_card_authorize_t));
    memcpy(&ops_passive_service_card_authorize[request->gun_number - OPSGUNNOA], request, sizeof(ops_passive_service_card_authorize_t));

    /* 出参 */
    (void)feedback;

    /* 处理 */
    OiovReqMain::SetCardAuthStartChargeService(request->gun_number - OPSGUNNOA);

    return 0;
}

void OiovCallback::RegisterCallback()
{
    /* 注册服务回调：APP启动充电 */
    OPS_RegisterCallback(OPS_ACTIVE_SERVICE_START_CHARGING_APP, callback_active_service_start_charging_app);

    /* 注册服务回调：APP停止充电 */
    OPS_RegisterCallback(OPS_ACTIVE_SERVICE_STOP_CHARGING_APP, callback_active_service_stop_charging_app);

    /* 注册服务回调：计费策略 */
    OPS_RegisterCallback(OPS_ACTICE_SERVICE_FEE_STRATEGY, callback_active_service_fee_strategy);

    /* 注册服务回调：时间同步 */
    OPS_RegisterCallback(OPS_ACTIVE_SERVICE_TIME_SYN, callback_active_service_time_syn);

    /* 注册服务回调：重启 */
    OPS_RegisterCallback(OPS_ACTIVE_SERVICE_REBOOT, callback_active_service_reboot);

    /* 注册服务回调：启动远程升级 */
    OPS_RegisterCallback(OPS_ACTIVE_SERVICE_START_UPDATE, callback_active_service_start_update);

    /* 注册服务回调：登录签到（充电桩接入认证） */
    OPS_RegisterCallback(OPS_PASSIVE_SERVICE_SIGN_IN, callback_passive_service_sign_in);

    /* 注册服务回调：登录签到（充电桩接入认证） */
    OPS_RegisterCallback(OPS_PASSIVE_SERVICE_FEE_CHECK, callback_passive_service_fee_check);
    /* 注册服务回调：心跳 */
    OPS_RegisterCallback(OPS_PASSIVE_SERVICE_HEARTBEAT, callback_passive_service_heartbeat);

    /* 注册服务回调：计费策略 */
    OPS_RegisterCallback(OPS_PASSIVE_SERVICE_FEE_STRATEGY, callbakc_passive_service_fee_strategy);

    /* 注册服务回调：账单 */
    OPS_RegisterCallback(OPS_PASSIVE_SERVICE_BILL, callback_passive_service_bill);

    /* 注册服务回调：充电桩主动申请充电 */
    OPS_RegisterCallback(OPS_PASSIVE_SERVICE_CARD_AUTH, callback_passive_card_auth);
}
